import { EquipControllerBase } from "./EquipControllerBase";
import { EItemUpdateOper } from "../../../Message/Game/EItemUpdateOper";
import { IView } from "../../mvc/interfaces/IView";
import { JewelModule } from "../../../modules/JewelModule";
import { EquipmentModuleConst } from "../view/equipment/data/EquipmentModuleConst";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
import { EPlayerItemPosType } from "../../../Message/Public/EPlayerItemPosType";
import { ItemData } from "../resource/info/ItemData";
import { Cache } from "../cache/Cache";
import { JewelUtil } from "../view/common/util/JewelUtil";
import { ItemConfig } from "../resource/ItemConfig";
import { JSON } from "../../../com/mui/serialization/json/JSON";
import { ECategory } from "../../../Message/Public/ECategory";
import { EProp } from "../../../Message/Public/EProp";
import { EBind } from "../../../Message/Public/EBind";
import { ItemInfo } from "../resource/info/ItemInfo";
import { Log } from "../../../com/gengine/debug/Log";
import { IJewelModule } from "../../../modules/interfaces/IJewelModule";
type int = number;
//class JewelController
    
    export  class JewelController extends EquipControllerBase
    {
        constructor()
        {
            
            super();_opertionType = EItemUpdateOper._EItemUpdateOperMakeHole;
            return;
        }

        protected /* override */ initView(): IView
        {
            if (!this._jewelModule) 
            {
                this._jewelModule = new JewelModule();
                addCommonListeners(this._jewelModule);
                this._jewelModule.addEventListener(EquipmentModuleConst.Event_ReChooseJewels, this.ReChooseJewels);
                this._jewelModule.addEventListener(EquipmentModuleConst.Event_ChoosedJewelChange, this.onChoosedJewelChange);
            }
            return this._jewelModule;
        }

        protected /* override */ initServer(): void
        {
            super.initServer();
            Dispatcher.addEventListener(EventName.JewelModuleOpenByIndex, this.openModuleByIndex);
            Dispatcher.addEventListener(EventName.Equipment_DoCast_MakeHole, this.doCastHandler);
            Dispatcher.addEventListener(EventName.Equipment_DoCast_EmbedJewel, this.doCastHandler);
            Dispatcher.addEventListener(EventName.Equipment_DoCast_RemoveJewel, this.doCastHandler);
            Dispatcher.addEventListener(EventName.Equipment_DoCast_ComposeJewel, this.doCastHandler);
            Dispatcher.addEventListener(EventName.SmeltJewelTransCountCost, this.onCountJewelTransCost);
            Dispatcher.addEventListener(EventName.SmeltJewelTransStarTrans, this.onStarTrans);
            Dispatcher.addEventListener(EventName.ComposeJewelOneKey_DoCompose, this.doOneKeyComposeJewel);
            Dispatcher.addEventListener(EventName.Guide_FirstPurplePetEquipmentStep2, this.onGuideFirstPurplePetEquipmentStep2Handler);
            return;
        }

        /* internal  */onChoosedJewelChange(arg1: DataEvent): void
        {
            _choosedJewels = arg1.data as Array<any>;
            updateEquipment();
            this.autoSelectedMaterial();
            return;
        }

        protected /* override */ useBindChangeHandler(arg1: DataEvent): void
        {
            cache.equipment.isUseBind_jewel = Boolean(arg1.data);
            super.useBindChangeHandler(arg1);
            return;
        }

        /* internal  */onCountJewelTransCost(arg1: DataEvent): void
        {
            if (this._jewelModule) 
            {
                this._jewelModule.updateJewelTransCost();
            }
            return;
        }

        /* internal  */onStarTrans(arg1: DataEvent): void
        {
            GameProxy.smelt.jewelTransform(arg1.data.jewelDic, arg1.data.targetJewelsDic);
            return;
        }

        /* internal  */doOneKeyComposeJewel(arg1: DataEvent): void
        {
            GameProxy.equipmentProxy.jewelOnceCompose(EPlayerItemPosType._EPlayerItemPosTypeStoneBag, arg1.data["autoBuy"], arg1.data["materials"]);
            return;
        }

        /* internal  */onGuideFirstPurplePetEquipmentStep2Handler(arg1: DataEvent): void
        {
            this._jewelModule.guideFirstPurplePetEquipment(true);
            return;
        }

        protected /* override */ onShowHandler(arg1: Object /* flash.events.Event */): void
        {
            super.onShowHandler(arg1);
            this._jewelModule.updateJewelTransCost();
            this._jewelModule.backPackItemChange();
            this._jewelModule.stoneBackpackItemChange();
            return;
        }

        protected /* override */ updateCost(arg1: Object=null): void
        {
            super.updateCost(arg1);
            if (this._jewelModule && !this._jewelModule.isHide) 
            {
                this._jewelModule.updateJewelTransCost();
            }
            return;
        }

        protected /* override */ serverBagDataChangehandler(arg1: Object=null): void
        {
            super.serverBagDataChangehandler(arg1);
            if (this._jewelModule && !this._jewelModule.isHide) 
            {
                this._jewelModule.backPackItemChange();
            }
            return;
        }

        protected /* override */ stoneBagDataChangehandler(arg1: Object=null): void
        {
            super.stoneBagDataChangehandler(arg1);
            if (this._jewelModule && !this._jewelModule.isHide) 
            {
                this._jewelModule.stoneBackpackItemChange();
            }
            return;
        }

        protected /* override */ checkEquipLost(): void
        {
            if (_opertionType != EItemUpdateOper._EItemUpdateComposeJewel) 
            {
                super.checkEquipLost();
            }
            else 
            {
                this.checkJewelLost();
            }
            return;
        }

        /* internal  */checkJewelLost(): void
        {
            var loc1=false;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=0;
            var loc6=0;
            if (_choosedMaterial && _choosedMaterial.length > 0) 
            {
                loc2 = cache.pack.stonePackCache.getJewelItems();
                loc3 = [];
                loc5 = 0;
                while (loc5 < _choosedMaterial.length) 
                {
                    loc1 = false;
                    if (loc4 = _choosedMaterial[loc5] as ItemData) 
                    {
                        loc6 = 0;
                        while (loc6 < loc2.length) 
                        {
                            if (loc4.uid == (loc2[loc6] as ItemData).uid && loc4.itemAmount == (loc2[loc6] as ItemData).itemAmount) 
                            {
                                loc1 = true;
                                break;
                            }
                            ++loc6;
                        }
                        if (!loc1) 
                        {
                            loc3.push(loc4);
                        }
                    }
                    ++loc5;
                }
                if (loc3.length > 0) 
                {
                    _view.update({"type":"equipmentLost", "data": loc3});
                }
            }
            return;
        }

        /* internal  */ReChooseJewels(arg1: DataEvent): void
        {
            var loc1=null;
            var loc4=0;
            var loc6=0;
            var loc7=0;
            var loc8=0;
            if (_opertionType != EItemUpdateOper._EItemUpdateComposeJewel) 
            {
                return;
            }
            var loc2=arg1.data;
            var loc3=Cache.instance.pack.stonePackCache.getJewelItems();
            loc4 = loc2.jewelNum;
            _choosedMaterial = [];
            var loc5=[];
            loc6 = 0;
            while (loc6 < loc3.length) 
            {
                loc1 = loc3[loc6] as ItemData;
                if (loc1.itemInfo.item.itemLevel <= 7) 
                {
                    if (loc1.uid == loc2.firstJewelUid) 
                    {
                        loc8 = Math.min(loc1.itemAmount, loc4);
                        loc7 = 0;
                        while (loc7 < loc8) 
                        {
                            _choosedMaterial[loc7] = loc1;
                            loc5[loc7] = {"item": loc1, "enough": true};
                            ++loc7;
                        }
                    }
                }
                else 
                {
                    if (loc1.uid == loc2.firstJewelUid) 
                    {
                        _choosedMaterial[0] = loc1;
                        loc5[0] = {"item": loc1, "enough": true};
                    }
                    if (loc1.uid == loc2.secondJewelUid) 
                    {
                        _choosedMaterial[1] = loc1;
                        loc5[1] = {"item": loc1, "enough": true};
                    }
                }
                ++loc6;
            }
            if (_choosedMaterial.length > 0 && JewelUtil.isNeedSpecialCompose(_choosedMaterial[0] as ItemData)) 
            {
                this.selectMaterialComposeJewel();
            }
            else 
            {
                _view.update({"type":"autoChooseMaterial", "material": loc5});
            }
            this.selectPropComposeJewel();
            this.selectMaterialComposeJewel();
            return;
        }

        protected /* override */ autoSelectedMaterial(): void
        {
            var loc1=_opertionType;
            switch (loc1) 
            {
                case EItemUpdateOper._EItemUpdateOperMakeHole:
                {
                    this.selectMaterialMakeHole();
                    break;
                }
                case EItemUpdateOper._EItemUpdateOperEmbedJewel:
                {
                    this.selectMaterialEmbedJewel();
                    break;
                }
                case EItemUpdateOper._EItemUpdateOperRemoveJewel:
                {
                    this.selectMaterialRemoveJewel();
                    break;
                }
                case EItemUpdateOper._EItemUpdateComposeJewel:
                {
                    this.selectMaterialComposeJewel();
                    break;
                }
                case EItemUpdateOper._EItemUpdateJewelAddance:
                {
                    this.selectMaterialJewelAdvance();
                    break;
                }
            }
            return;
        }

        /* internal  */selectMaterialMakeHole(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=null;
            var loc6=null;
            var loc12=0;
            var loc13=null;
            var loc14=null;
            var loc7=[];
            if (choosedEquipmentData.length == 0) 
            {
                return;
            }
            var loc8;
            var loc9=(loc8 = _choosedEquipmentData[0] as ItemData).itemExInfo.hole1;
            var loc10=loc8.itemExInfo.hole2;
            var loc11=loc8.itemExInfo.hole3;
            if (loc9 != 0) 
            {
                if (loc10 != 0) 
                {
                    if (loc11 == 0) 
                    {
                        loc12 = 3;
                    }
                }
                else 
                {
                    loc12 = 2;
                }
            }
            else 
            {
                loc12 = 1;
            }
            loc2 = ItemConfig.instance.getUpdateInfo(ItemConfig.WeaponMakeHole, loc12)["condition"];
            loc1 = JSON.deserialize(loc2);
            loc3 = Cache.instance.pack.backPackCache.getPropItems();
            loc4 = 0;
            while (loc4 < loc3.length) 
            {
                if ((loc5 = loc3[loc4] as ItemData).category == ECategory._ECategoryProp && loc5.itemInfo.item.type == EProp._EPropEquipMakeHoleRune && loc1["level"] == loc5.itemInfo.item.itemLevel) 
                {
                    if (!(!_useBind && loc5.bind == EBind._EBindYes)) 
                    {
                        loc7.push({"data": loc5, "bind": loc5.itemInfo.item.bind});
                    }
                }
                ++loc4;
            }
            if (loc7.length > 0) 
            {
                if (_useBind) 
                {
                    loc7.sortOn("bind", Array.DESCENDING);
                }
                else 
                {
                    loc7.sortOn("bind");
                }
                loc6 = loc7[0]["data"];
                _view.update({"type":"autoChooseMaterial", "material":[loc6], "isEnough": true});
            }
            else 
            {
                loc13 = [];
                loc14 = ItemConfig.instance.getPropsByType(EProp._EPropEquipMakeHoleRune);
                loc4 = 0;
                while (loc4 < loc14.length) 
                {
                    if ((loc5 = new ItemData((loc14[loc4] as ItemInfo).item.code)).itemInfo.item.bind == EBind._EBindNo && loc5.itemInfo.item.itemLevel == loc1["level"]) 
                    {
                        loc13.push(loc5);
                        break;
                    }
                    ++loc4;
                }
                _view.update({"type":"autoChooseMaterial", "material": loc13, "isEnough": false});
            }
            return;
        }

        /* internal  */selectMaterialEmbedJewel(): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            if (!_choosedMaterial) 
            {
                return;
            }
            loc2 = 0;
            while (loc2 < _choosedMaterial.length) 
            {
                _choosedMaterial[loc2].materialData = null;
                ++loc2;
            }
            loc5 = this.getUsedMaterialNum();
            loc2 = 0;
            while (loc2 < _choosedMaterial.length) 
            {
                loc1 = _choosedMaterial[loc2].jewelData;
                if (loc1 && !_choosedMaterial[loc2].materialData) 
                {
                    loc3 = this.getMaterialByJewel(loc1, loc5);
                    loc4 = loc3["materialData"];
                    _choosedMaterial[loc2].isEnough = loc3["isEnough"];
                    _choosedMaterial[loc2].materialData = loc4;
                    if (loc4) 
                    {
                        if (loc5[loc4.uid]) 
                        {
                            var loc6;
                            var loc7;
                            var loc8=((loc6 = loc5)[loc7 = loc4.uid] + 1);
                            loc6[loc7] = loc8;
                        }
                        else 
                        {
                            loc5[loc4.uid] = 1;
                        }
                    }
                }
                ++loc2;
            }
            _view.update({"type":"autoChooseMaterial", "material": _choosedMaterial});
            return;
        }

        /* internal  */selectMaterialRemoveJewel(): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            var loc5=new Object();
            if (!_choosedMaterial) 
            {
                return;
            }
            loc2 = 0;
            while (loc2 < _choosedMaterial.length) 
            {
                loc1 = _choosedMaterial[loc2].jewelData;
                if (loc1) 
                {
                    loc3 = this.getMaterialByJewel(_choosedMaterial[loc2].jewelData, loc5);
                    loc4 = loc3["materialData"];
                    _choosedMaterial[loc2].isEnough = loc3["isEnough"];
                    _choosedMaterial[loc2].materialData = loc4;
                    _choosedMaterial[loc2].material = loc4;
                    if (loc4) 
                    {
                        if (loc5[loc4.uid] == null) 
                        {
                            loc5[loc4.uid] = 1;
                        }
                        else 
                        {
                            var loc6;
                            var loc7;
                            var loc8=((loc6 = loc5)[loc7 = loc4.uid] + 1);
                            loc6[loc7] = loc8;
                        }
                    }
                }
                else 
                {
                    _choosedMaterial[loc2].material = null;
                    _choosedMaterial[loc2].isEnough = true;
                }
                ++loc2;
            }
            _view.update({"type":"autoChooseMaterial", "material": _choosedMaterial});
            return;
        }

        /* internal  */selectMaterialComposeJewel(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc7=null;
            if (_choosedMaterial.length > 0) 
            {
                loc1 = _choosedMaterial[0] as ItemData;
                if (loc1.itemInfo.item.itemLevel == 8) 
                {
                    this._jewelModule.clickJewel(loc1);
                }
                if (JewelUtil.isNeedSpecialCompose(loc1) && _choosedMaterial.length == 2) 
                {
                    loc2 = [];
                    if (JewelUtil.isNormalJewel(loc1)) 
                    {
                        loc2 = cache.pack.backPackCache.getPropByType(EProp._EPropGradeEightJewelCompoMaterial);
                    }
                    else if (loc1.itemInfo.item.itemLevel <= 7) 
                    {
                        loc2 = cache.pack.backPackCache.getPropByType(EProp._EPropGradeSpecailJewelCompoMaterial);
                    }
                    else 
                    {
                        loc2 = cache.pack.backPackCache.getPropByType(EProp._EPropGradeDoubleJewelCompoMaterial);
                    }
                    loc5 = [];
                    loc6 = 0;
                    loc3 = 0;
                    while (loc3 < loc2.length) 
                    {
                        if ((loc4 = loc2[loc3] as ItemData).itemInfo.item.itemLevel == loc1.itemInfo.item.itemLevel) 
                        {
                            loc5.push(loc4);
                            loc6 = loc6 + loc4.itemAmount;
                        }
                        ++loc3;
                    }
                    if (_useBind) 
                    {
                        loc5.sortOn("bind", Array.DESCENDING);
                    }
                    else 
                    {
                        loc5.sortOn("bind");
                    }
                    (loc7 = []).push({"item": _choosedMaterial[0], "enough": true});
                    loc7.push({"item": _choosedMaterial[1], "enough": true});
                    if (JewelUtil.isNormalJewel(loc1)) 
                    {
                        loc4 = new ItemData(ItemConfig.instance.getItemByTypeAndLevel(ECategory._ECategoryProp, EProp._EPropGradeEightJewelCompoMaterial, -1, loc1.itemInfo.item.itemLevel).item.code);
                    }
                    else if (loc1.itemInfo.item.itemLevel <= 7) 
                    {
                        loc4 = new ItemData(ItemConfig.instance.getItemByTypeAndLevel(ECategory._ECategoryProp, EProp._EPropGradeSpecailJewelCompoMaterial, -1, loc1.itemInfo.item.itemLevel).item.code);
                    }
                    else 
                    {
                        loc4 = new ItemData(ItemConfig.instance.getItemByTypeAndLevel(ECategory._ECategoryProp, EProp._EPropGradeDoubleJewelCompoMaterial, -1, loc1.itemInfo.item.itemLevel).item.code);
                    }
                    if (loc6 != 0) 
                    {
                        if (loc6 != 1) 
                        {
                            if (loc5[0].itemAmount != 1) 
                            {
                                loc7.push({"item": loc5[0], "enough": true});
                                loc7.push({"item": loc5[0], "enough": true});
                            }
                            else 
                            {
                                loc7.push({"item": loc5[0], "enough": true});
                                loc7.push({"item": loc5[1], "enough": true});
                            }
                        }
                        else 
                        {
                            loc7.push({"item": loc5[0], "enough": true});
                            loc7.push({"item": loc4, "enough": false});
                        }
                    }
                    else 
                    {
                        loc7.push({"item": loc4, "enough": false});
                        loc7.push({"item": loc4, "enough": false});
                    }
                    _view.update({"type":"autoChooseMaterial", "material": loc7});
                }
                else if (JewelUtil.isNeedSpecialCompose(loc1) && _choosedMaterial.length == 1) 
                {
                    _view.update({"type":"autoChooseMaterial", "material":[{"item": _choosedMaterial[0], "enough": true}]});
                }
            }
            this.selectPropComposeJewel();
            return;
        }

        /* internal  */selectPropComposeJewel(): void
        {
            var loc1=0;
            var loc5=null;
            var loc7=null;
            var loc8=null;
            var loc9=null;
            if (!_choosedMaterial || _choosedMaterial.length < 2 || _choosedMaterial.length < 3 && !JewelUtil.isNeedSpecialCompose(_choosedMaterial[0] as ItemData)) 
            {
                _view.update({"type":"autoChooseLuckTune", "luckTune":[], "isEnough": true});
                return;
            }
            var loc2=[];
            var loc3=[];
            if (!(_choosedMaterial.length > 0 && _choosedMaterial[0] is ItemData)) 
            {
                return;
            }
            var loc4=_choosedMaterial[0] as ItemData;
            var loc6=cache.pack.backPackCache.getPropItems();
            loc1 = 0;
            while (loc1 < loc6.length) 
            {
                if ((loc5 = loc6[loc1] as ItemData).category == ECategory._ECategoryProp && loc5.itemInfo.item.type == EProp._EPropJewelComposeRune && loc5.itemInfo.item.effectEx >= loc4.itemInfo.item.itemLevel && loc5.itemInfo.item.effect <= loc4.itemInfo.item.itemLevel) 
                {
                    if (!(!_useBind && loc5.bind == EBind._EBindYes)) 
                    {
                        loc3.push({"data": loc5, "bind": loc5.itemInfo.item.bind});
                    }
                }
                ++loc1;
            }
            if (_useBind) 
            {
                loc3.sortOn("bind", Array.DESCENDING);
            }
            else 
            {
                loc3.sortOn("bind");
            }
            if (loc3.length > 0) 
            {
                var loc10=0;
                var loc11=loc3;
                for(loc7 of loc11) 
                {
                    loc2.push(loc7["data"]);
                }
                _view.update({"type":"autoChooseLuckTune", "luckTune": loc2, "isEnough": true});
            }
            else 
            {
                loc9 = ItemConfig.instance.getPropsByType(EProp._EPropJewelComposeRune);
                loc1 = 0;
                while (loc1 < loc9.length) 
                {
                    if ((loc5 = new ItemData((loc9[loc1] as ItemInfo).item.code)).itemInfo.item.bind == EBind._EBindNo && loc5.itemInfo.item.effectEx >= loc4.itemInfo.item.itemLevel && loc5.itemInfo.item.effect <= loc4.itemInfo.item.itemLevel) 
                    {
                        loc8 = loc5;
                        break;
                    }
                    ++loc1;
                }
                loc2.push(loc8);
                _view.update({"type":"autoChooseLuckTune", "luckTune": loc2, "isEnough": false});
            }
            return;
        }

        /* internal  */selectMaterialJewelAdvance(): void
        {
            var loc2=0;
            var loc4=null;
            if (_choosedJewels.length == 0) 
            {
                _view.update({"type":"autoChooseMaterial", "material":[]});
                return;
            }
            var loc1=_choosedJewels[0] as ItemData;
            var loc3=[];
            var loc5=Cache.instance.pack.backPackCache.getPropItems();
            loc2 = 0;
            while (loc2 < loc5.length) 
            {
                if ((loc4 = loc5[loc2] as ItemData).category == ECategory._ECategoryProp && loc4.itemInfo.item.type == EProp._EPropJewelAdvance && loc4.itemInfo.item.itemLevel == loc1.itemInfo.item.itemLevel) 
                {
                    if (!(!_useBind && loc4.bind == EBind._EBindYes)) 
                    {
                        loc3.push(loc4);
                    }
                }
                ++loc2;
            }
            if (_useBind) 
            {
                loc3.sortOn("bind", Array.DESCENDING);
            }
            else 
            {
                loc3.sortOn("bind");
            }
            _view.update({"type":"autoChooseMaterial", "material": loc3});
            return;
        }

        /* internal  */getMaterialByJewel(arg1: ItemData, arg2: Object): Object
        {
            var loc3=null;
            var loc4=null;
            var loc6=0;
            var loc8=0;
            var loc9=null;
            var loc1=arg1.itemInfo.item.itemLevel;
            var loc2=Cache.instance.pack.backPackCache.getPropItems();
            var loc5=[];
            var loc7=loc2.length;
            if (_opertionType != EItemUpdateOper._EItemUpdateOperEmbedJewel) 
            {
                if (_opertionType == EItemUpdateOper._EItemUpdateOperRemoveJewel) 
                {
                    loc8 = EProp._EPropEquipRemoveRune;
                }
            }
            else 
            {
                loc8 = EProp._EPropEquipEmbedRune;
            }
            loc6 = 0;
            while (loc6 < loc7) 
            {
                if ((loc3 = loc2[loc6] as ItemData).category == ECategory._ECategoryProp && loc3.itemInfo.item.type == loc8 && loc1 >= loc3.itemInfo.item["effect"] && loc1 <= loc3.itemInfo.item["effectEx"] && (!arg2[loc3.uid] || arg2[loc3.uid] < loc3.itemAmount)) 
                {
                    if (!(!_useBind && loc3.bind == EBind._EBindYes)) 
                    {
                        loc5.push({"data": loc3, "bind": loc3.itemInfo.item.bind});
                    }
                }
                ++loc6;
            }
            if (loc5.length > 0) 
            {
                if (_useBind) 
                {
                    loc5.sortOn("bind", Array.DESCENDING);
                }
                else 
                {
                    loc5.sortOn("bind");
                }
                if ((loc4 = loc5[0]["data"]).itemInfo.item["effect"] > loc1) 
                {
                    Log.system("选取了高级的材料");
                }
                return {"materialData": loc4, "isEnough": true};
            }
            loc9 = ItemConfig.instance.getPropsByType(loc8);
            loc6 = 0;
            while (loc6 < loc9.length) 
            {
                if ((loc3 = new ItemData((loc9[loc6] as ItemInfo).item.code)).itemInfo.item.bind == EBind._EBindNo && loc1 >= loc3.itemInfo.item["effect"] && loc1 <= loc3.itemInfo.item["effectEx"]) 
                {
                    return {"materialData": loc3, "isEnough": false};
                }
                ++loc6;
            }
            return {"materialData": null, "isEnough": false};
        }

        /* internal  */getUsedMaterialNum(): Object
        {
            var loc3=null;
            var loc1={};
            var loc2=0;
            while (loc2 < _choosedMaterial.length) 
            {
                loc3 = _choosedMaterial[loc2].materialData;
                if (loc3) 
                {
                    if (loc1[loc3.uid]) 
                    {
                        var loc4;
                        var loc5;
                        var loc6=((loc4 = loc1)[loc5 = loc3.uid] + 1);
                        loc4[loc5] = loc6;
                    }
                    else 
                    {
                        loc1[loc3.uid] = 1;
                    }
                }
                ++loc2;
            }
            return loc1;
        }

        /* internal  */openModuleByIndex(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            if (this.view.isHide) 
            {
                this.view.show();
            }
            (this._jewelModule as JewelModule).gotoPanel(loc1);
            return;
        }

        protected /* override */ doCastHandler(arg1: DataEvent): void
        {
            if (view.isHide) 
            {
                view.show();
            }
            var loc1=arg1.type;
            switch (loc1) 
            {
                case EventName.Equipment_DoCast_MakeHole:
                {
                    showToPanel(EItemUpdateOper._EItemUpdateOperMakeHole);
                    if (arg1.data) 
                    {
                        _view.update({"type":"doCast", "data": arg1.data as ItemData});
                    }
                    break;
                }
                case EventName.Equipment_DoCast_EmbedJewel:
                {
                    showToPanel(EItemUpdateOper._EItemUpdateOperEmbedJewel);
                    if (arg1.data) 
                    {
                        _view.update({"type":"doCast", "data": arg1.data as ItemData});
                    }
                    break;
                }
                case EventName.Equipment_DoCast_RemoveJewel:
                {
                    showToPanel(EItemUpdateOper._EItemUpdateOperRemoveJewel);
                    if (arg1.data) 
                    {
                        _view.update({"type":"doCast", "data": arg1.data as ItemData});
                    }
                    break;
                }
                case EventName.Equipment_DoCast_ComposeJewel:
                {
                    showToPanel(EItemUpdateOper._EItemUpdateComposeJewel);
                    if (arg1.data) 
                    {
                        _view.update({"type":"doCast", "data": arg1.data as ItemData});
                    }
                    break;
                }
            }
            return;
        }

        private /* var */_jewelModule: IJewelModule;
    }
